﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyKhachSan.BusinessLogic;
using QuanLyKhachSan.BusinessObject;
using QuanLyKhachSan.DataAccess;
namespace QuanLyKhachSan
{
    public partial class frmLoaiPhong : Form
    {
        private LoaiPhongBL lpBL = new LoaiPhongBL();
        private LoaiPhongBO lpBO = new LoaiPhongBO();
        string loaiphong = null;
        public frmLoaiPhong()
        {
            InitializeComponent();
        }

        private void frmLoaiPhong_Load(object sender, EventArgs e)
        {
            dgvwLoaiPhong.DataSource = lpBL.LayDSLoaiPhong();
            
        }

        // Load dữ liệu từ datagredview lên textbox
        private void dgvwLoaiPhong_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
            lpBO.STT = int.Parse(dgvwLoaiPhong.Rows[dong].Cells["STT"].Value.ToString());
            lpBO.MaLoaiPhong = dgvwLoaiPhong.Rows[dong].Cells["MaloaiPhong"].Value.ToString();
            lpBO.TenLoaiPhong = dgvwLoaiPhong.Rows[dong].Cells["TenLoaiPhong"].Value.ToString();
            lpBO.KieuPhong = dgvwLoaiPhong.Rows[dong].Cells["KieuPhong"].Value.ToString();
            lpBO.ChatLuong = dgvwLoaiPhong.Rows[dong].Cells["ChatLuong"].Value.ToString();
            lpBO.DonGia = int.Parse(dgvwLoaiPhong.Rows[dong].Cells["DonGia"].Value.ToString());
        }


        private void LayDuLieu(LoaiPhongBO LP)
        {
            this.loaiphong = LP.MaLoaiPhong;
            if (!loaiphong.Equals(""))
            {
                dgvwLoaiPhong.DataSource = lpBL.LayDSLoaiPhong();
            }
        }
       
        

        private void btnThem_Click_1(object sender, EventArgs e)
        {
            frmAddLoaiPhong falp = new frmAddLoaiPhong();
            falp.NextID();
            falp.DuLieu = new frmAddLoaiPhong.DuLieuTruyenVe(LayDuLieu);
            falp.Show();
        }

        private void btnSua_Click_1(object sender, EventArgs e)
        {
            frmAddLoaiPhong falp = new frmAddLoaiPhong();

            falp.Load_Edit(lpBO);
            falp.DuLieu = new frmAddLoaiPhong.DuLieuTruyenVe(LayDuLieu);
            falp.Show();
        }

        private void btnXoa_Click_1(object sender, EventArgs e)
        {
            if (lpBO.MaLoaiPhong == "")
                MessageBox.Show("Chọn mã nhân viên", "Chương trình thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa hay không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    lpBL.Delete(lpBO.MaLoaiPhong);
                    frmLoaiPhong_Load(sender, e);
                }
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            bool kq = (MessageBox.Show("Bạn có chắc chắn muốn thoát không ? ", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes);
            if (kq == true)
            {
                this.Close();
            }
        }

        private void txtTimKiem_KeyUp(object sender, KeyEventArgs e)
        {
            dgvwLoaiPhong.DataSource = lpBL.TimKiemLoaiPhong(txtTimKiem.Text);
        }
        
        
    }
}
